package com.zyz.sunliky.controller;

import com.zyz.sunliky.common.ResultCommon;
import com.zyz.sunliky.service.SupplierService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static com.zyz.sunliky.util.ProConstans.HGGYS;


@RequestMapping("/supplier")
@RestController
public class SupplierController {

    public static final Logger logger = LoggerFactory.getLogger(SupplierController.class);

    @Autowired
    SupplierService supplierService;
    /**
     * 供应商获取订单信息
     * @param supplierNo
     * @return
     */
    @GetMapping("/orderInfo")
    public Map getInventory(String supplierNo, @RequestParam(required = false) Integer  page, Integer  rows){
        try {
            return supplierService.getOrderInfo(supplierNo,page,rows);
        }catch (Exception e){
            Map map = new HashMap();
            e.printStackTrace();
            logger.error(e.getMessage());
            map.put("count",0);
            map.put("data",new ArrayList<>());
            return map;
        }

    }

    /**
     * 供应商基础信息建立
     * @param id
     * @return
     */
    @GetMapping("/supplier")
    public ResultCommon getSupplier(String id,String type){
        try {
            if (HGGYS.equals(type)){
                supplierService.getSupplier(id);
            }
            return new ResultCommon("",200,"成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return new ResultCommon(null,500,e.getMessage());
        }

    }



    @GetMapping ("/getName")
    //@CrossOrigin
    public String projectNum(String projectType){

        String projectNum = supplierService.projectNum(projectType);
            return  projectNum;
    }

}
